define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user_assets/index' + location.search,
                    add_url: 'user_assets/add',
                    edit_url: 'user_assets/edit',
                    del_url: 'user_assets/del',
                    multi_url: 'user_assets/multi',
                    import_url: 'user_assets/import',
                    table: 'user_assets',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'mine_user.username', title: __('用户邮箱')},
                        {field: 'mine_user.nickname', title: __('昵称')},
                        {field: 'usdt', title: __('UDST'), operate: 'BETWEEN'},
                        {field: 'usdt_address', title: __('tron地址'), operate: false},
                        {field: 'btc', title: __('Btc'), operate: 'BETWEEN'},
                        {field: 'btc_address', title: __('BTC地址')},
                        {field: 'bch', title: __('Bch'), operate: 'BETWEEN'},
                        {field: 'bch_address', title: __('BCH地址'), operate: 'BETWEEN'},
                        {field: 'ltc', title: __('Ltc'), operate: 'BETWEEN'},
                        {field: 'ltc_address', title: __('LTC地址'), operate: 'BETWEEN'},
                        {field: 'etc', title: __('Etc'), operate: 'BETWEEN'},
                        {field: 'etc_address', title: __('ETC地址'), operate: 'BETWEEN'},
                        {field: 'zec', title: __('Zec'), operate: 'BETWEEN'},
                        {field: 'zec_address', title: __('ZEC地址'), operate: 'BETWEEN'},
                        {field: 'dash', title: __('Dash'), operate: 'BETWEEN'},
                        {field: 'dash_address', title: __('DASH地址'), operate: 'BETWEEN'},
                        //s   {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //     {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons:[
                                {
                                    name: 'detail',
                                    text: __('打钱'),
                                    title: __('打钱'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'user_assets/remit',
                                    callback: function (data) {
                                        // Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'user_assets/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'user_assets/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'user_assets/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        remit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
